{template '/hairsalon/header'}
<Style>
    body{background: #EEE}
    .mainbody{}
    .page_left{float: left;width: 34px; background: #293038}
    .page_left .menu-text,.page_left b{display:none}
    .page_middle{padding: 15px; height: 100%;  overflow-y: scroll;}
    ul.left_nav{}
    ul.left_nav li a{padding:10px;display: block;color:#FFF;}
    ul.left_nav li a:hover,ul.left_nav li a:active{background:#09c }
    ul.left_nav li a i{ display: inline-block;width: 30px; text-align: left;}
    ul.left_nav li a .menu-text{font-size:14px;}
    ul.left_nav li a b{float:right; font-size: 10px;margin-top: 3px}
    .panel{margin-bottom: 10px;}
    #maincontainer{ position: relative;}
    .projectbox{overflow-y: scroll}
    #goodprolist td{vertical-align: middle}
    #staffselect{position: absolute;z-index: 2;}
    .footbar{position: absolute;left: 0;right:0;bottom: 0; height:60px;margin-bottom: 0}
    .countbar{display: inline-block; margin-right: 20px;font-size:18px; line-height: 20px;}
    .countbar small{font-size: 12px;color: #F60}
    #totalfee{color: #F60; font-family: Arial;font-size: 24px;}
    .btnmemberbox{display: inline-block;font-size:10px;padding:5px 10px;width:160px;}
    header .layui-nav-item dd{line-height: 30px;}
    #root_timer{font-size: 20px;font-family:Arial;}
</Style>
<header class="navbar" style="margin: 0;border-radius: 0;background: #1E9FFF;">
    <div class="navbar-inner">
        <div class="container-fluid">
            <div class="pull-left" style="line-height:60px;">
                <img src="{php echo tomedia($cfg['logo'])}" onerror="this.style.display='none'" style="margin: 3px 0 0 18px; height:35px;">
            </div>
            <ul class="layui-nav pull-right layui-bg-blue" lay-filter="">
                <li class="layui-nav-item"><a href="javascript:" id="root_timer"></a></li>
                <li class="layui-nav-item"><a href="javascript:">{$user['realname']}</a></li>
                <!--li class="layui-nav-item"><a href="{$_W['siteroot']}/web/index.php?c=site&a=entry&do=shop&m=j_hmoney&i={$_W['uniacid']}" target="_blank">系统后台</a></li-->
				<li class="layui-nav-item"><a href="../app/index.php?i=1&c=entry&do=loginadmin&m=j_hmoney" target="_blank">系统后台</a></li>
                <li class="layui-nav-item"><a href="javascript:funExtend_history()">订单</a></li>
                <li class="layui-nav-item"> <a href="javascript:funExtend_member();">会员</a>
                    <dl class="layui-nav-child" style="right:0;left:auto">
                        <dd><a href="javascript:funExtend_charge();">充值</a></dd>
                        <dd><a href="javascript:funExtend_sellcard()">次卡销售</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item"> <a href="javascript:;">管理</a>
                    <dl class="layui-nav-child" style="right:0;left:auto">
                        <dd><a href="javascript:funSys_changepass()"><i class="fa fa-lock"></i> 修改密码</a></dd>
                        <dd><a href="javascript:funSys_handover()"><i class="fa fa-off"></i> 退出</a></dd>
                    </dl>
                </li>
            </ul>
        </div>
    </div>
</header>
<section class="mainbody">
  <aside class="page_middle">
      <div id="maincontainer">
          <div class="panel panel-info">
              <div class="panel-body">
                  <div class="row">
                      <div class="col-md-6 col-sm-6 ">
                          <div class="input-group">
                              <span class="input-group-addon">项目</span>
                              <input type="text" class="form-control" placeholder="请输入编号/名称" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true" id="search_project" oninput="fun_searchgood(this)" />
                              <ul class="dropdown-menu">
                                  {loop $projectlist $row}
                                  <li><a href="JavaScript:addnewproject(1,{$row['id']})">{$row['title']}</a></li>
                                  {/loop}
                              </ul>
                              <span class="input-group-btn"><button class="btn btn-default" type="button">选择</button></span>
                          </div>
                      </div>
                      <div class="col-md-6 col-sm-6">
                          <div class="input-group">
                              <span class="input-group-addon">商品</span>
                              <input type="text" class="form-control" placeholder="请输入编号/名称" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true" oninput="fun_searchgood(this)" id="search_goods"  />
                              <ul class="dropdown-menu">
                                  {loop $goodlist $row}
                                  <li><a href="JavaScript:addnewproject(2,{$row['id']})">{$row['title']}</a></li>
                                  {/loop}
                              </ul>
                              <span class="input-group-btn"><button class="btn btn-default" type="button">选择</button></span>
                          </div>
                      </div>
                      <!--<div class="col-md-4 col-sm-4">-->
                          <!--<div class="input-group">-->
                              <!--<span class="input-group-addon">会员</span>-->
                              <!--<input type="text" class="form-control" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true" oninput="fun_searchmember(this)" placeholder="请输入卡号/电话/姓名"/>-->
                              <!--<ul class="dropdown-menu">-->

                              <!--</ul>-->
                              <!--<span class="input-group-btn"><button class="btn btn-default" type="button">选择</button></span>-->
                          <!--</div>-->
                      <!--</div>-->
                  </div>
              </div>
          </div>

          <div class="panel panel-default projectbox">
              <input type="hidden" id="orderid" value=""/>
              <div class="panel panel-heading">项目列表 NO：<span id="orderno">请先开单</span></div>
              <table class="table table-hover table-bordered">
                  <thead>
                  <tr>
                      <th style="width:130px">项目名称</th>
                      <th>员工</th>
                      <th style="width:100px">方式</th>
                      <th style="width:70px">提成额</th>
                      <th style="width:90px">业绩</th>
                      <th style="width:90px">单价</th>
                      <th style="width:60px">数量</th>
                      <th style="width:80px">折扣</th>
                      <th style="width:100px">折后额</th>
                      <th style="text-align:right;width:60px">操作</th>
                  </tr>
                  </thead>
                  <tbody id="goodprolist">

                  </tbody>
                  <tr>
                      <td colspan="10"></td>
                  </tr>
              </table>
          </div>
          <div class="panel panel-warning footbar">
              <div class="panel-body" style="padding: 5px 15px">
                  <div class="row">
                      <div class="col-md-6 col-sm-6">
                          <button type="button" class="btn btn-warning btn-lg" onclick="fun_selectholdorder()" style="width: 120px">取单</button><input type="hidden" id="membercardno" value="0"/>
                          <span id="membercardbox" style="display:none">


                          </span>

                      </div>
                      <div class="col-md-6 text-right col-sm-6">
                          <span class="countbar">
                              总金额：<small>￥</small><span id="totalfee">0.00</span>
                          </span>
                          <button type="button" class="btn btn-info btn-lg" onclick="fun_holdOrder();" id="holdorder" style="width: 120px">开单</button>
                          <button type="button" class="btn btn-danger btn-lg" onclick="fun_startPay()" style="width: 120px">收款</button>
                      </div>
                  </div>
              </div>
          </div>
      </div>
  </aside>
</section>
<div id="staffselect" style="display:none">
    <ul class="dropdown-menu">

    </ul>
</div>
<style>
    .modal_selectorder {padding:15px 0;}
    .modal_selectorderbox{ padding:10px; background:#FFF;}
    .modal_selectorderbox ul{ height:400px; overflow:hidden;border:1px solid #CCC;}
    .modal_selectorderbox ul li{ padding:10px; border-bottom:1px solid #CCC; cursor:pointer;}
    .modal_selectorderbox ul li.isselect{ background:#e3eff5}

</style>
<div class="modal_selectorder" style="display:none;">
    <div class="modal_selectorderbox">
        <div class="pull-left" style="width:260px;margin-right:10px;">
            <ul class="dragscroll modal_selectorderlist">

            </ul>
        </div>
        <div class="pull-right" style="width:470px;">
            <ul class="dragscroll">
                <table class="layui-table" lay-even lay-skin="nob" style="margin:0">
                    <thead>
                    <tr>
                        <th>条码</th>
                        <th>名称</th>
                        <th>数量</th>
                        <th>金额</th>
                    </tr>
                    </thead>
                    <tbody class="modal_selectorderlist2">

                    </tbody>
                </table>
            </ul>
        </div>

    </div>
    <div class="text-right" style="padding:10px 20px; clear:both">
        <button type="button" class="layui-btn layui-btn-small layui-btn-normal modal_selectorderbtn1 " style="width:90px">取回 </button>
        <button type="button" class="layui-btn layui-btn-small layui-btn-danger modal_selectorderbtn2 " style="width:90px"> 删除 </button>
        <button type="button" class="layui-btn layui-btn-small layui-btn-primary modal_selectorderbtn3 " style="width:90px"> 关闭</button>
    </div>
</div>

<style>
    .modal_counter{background:#EEE;padding:15px;}
    .moad_inputbox{ margin-bottom:15px; position:relative;}
    .moad_inputbox input{ border:none;box-shadow:0 0 3px #ddd; border-radius:4px; text-align:right;font-family: 微软雅黑;font-size: 25px;font-weight: bold;color: rgb(102, 102, 102); width:100%; padding:5px 52px 5px 0}
    .moad_inputbox span{ position:absolute; right:15px; top:10px; line-height:25px;font-size:25px;color:#CCC}
    .modal_counter .modal_body{ padding:0; overflow:hidden}
    .modal_counter .modal_body a{ display:block; line-height:55px;box-shadow:0 0 4px #CCC; border-radius:4px; background:#FFF;font-size:25px; text-align:center;}
    .bl{ display:inline-block; width:190px}
    .bl li{ display:inline-block;width:55px;margin-right:5px;margin-bottom:8px}
    .br{ float:right}
    .br li{ width:80px;}
    .modal_btn_big{height:110px; width:110px; text-align:center; border:1px solid #CCC; border-radius:4px; margin:5px;font-size:24px; background:#FFF}
    .modal_btn_big:active,.modal_btn_big:hover{ background:#F66; color:#FFF; }
    .modal_tastebox{ text-align:center; padding:10px;}
    .modal_tastebox span{ border:1px solid #CCC; display:inline-block; padding:5px; min-width:60px; margin:5px; text-align:center; border-radius:4px; cursor:pointer}
    .modal_tastebox span.isselect{ border-color:#90b82d; background:#90b82d; color:#FFF;}
    .modal_customgoodbox{ text-align:center; padding:10px;}
    .modal_customgoodbox span{ border:1px solid #CCC; display:inline-block; padding:5px; min-width:60px; margin:5px; text-align:center; border-radius:4px; cursor:pointer}
    .modal_customgoodbox span.isselect{ border-color:#90b82d; background:#90b82d; color:#FFF;}
</style>
<div class="modal_counter" style="display:none;">
    <div class="moad_inputbox">
        <input type="text" id="moadConterInput" maxlength="10" />
        <span onclick="$('#moadConterInput').val('')"><i class="fa fa-remove-sign"></i></span>
    </div>
    <div class="modal_body">
        <div class="bl">
            <ul>
                <li><a href="javascript:" onclick="Counter(7,'#moadConterInput')">7</a></li>
                <li><a href="javascript:" onclick="Counter(8,'#moadConterInput')">8</a></li>
                <li><a href="javascript:" onclick="Counter(9,'#moadConterInput')">9</a></li>
                <li><a href="javascript:" onclick="Counter(4,'#moadConterInput')">4</a></li>
                <li><a href="javascript:" onclick="Counter(5,'#moadConterInput')">5</a></li>
                <li><a href="javascript:" onclick="Counter(6,'#moadConterInput')">6</a></li>
                <li><a href="javascript:" onclick="Counter(1,'#moadConterInput')">1</a></li>
                <li><a href="javascript:" onclick="Counter(2,'#moadConterInput')">2</a></li>
                <li><a href="javascript:" onclick="Counter(3,'#moadConterInput')">3</a></li>
                <li style="width:120px"><a href="javascript:" onclick="Counter(0,'#moadConterInput')">0</a></li>
                <li id="modal_doc"><a href="javascript:" onclick="Counter('.','#moadConterInput')">.</a></li>
            </ul>
        </div>
        <div class="br">
            <li style="margin-bottom:8px"><a href="javascript:" id="modal_cantrl"  style=" background:#50a4ec;font-size:20px;color:#FFF">取消</a></li>
            <li><a href="javascript:" id="modal_sure"  style=" background:#1bb987;font-size:24px;color:#FFF; height:180px; padding-top:40px">确<br/>定</a></li>
        </div>
    </div>
</div>
{template $cfg['floder'].'/tpl_charge'}
{template $cfg['floder'].'/tpl_member'}
{template $cfg['floder'].'/tpl_sellcard'}
{template $cfg['floder'].'/tpl_paybox'}
{template $cfg['floder'].'/tpl_history'}
{template $cfg['floder'].'/tpl_sys'}
<script language="JavaScript">
    $(document).ready(function(){
        startPos();
    });
    function startPos(){
        var _h=$(window).height()-50;
        $(".page_left").height(_h);
        $("#maincontainer").height(_h-30);
        $(".projectbox").height(_h-180);
    }
    var staffcateAry=eval('('+'{php echo json_encode($staffcateAry)}'+')');
    var stafflist=eval('('+'{php echo json_encode($staffAry)}'+')');
    layui.use(['layer', 'laypage', 'element','form'], function() {
        var layer = layui.layer
                , laypage = layui.laypage
                , element = layui.element
                , form = layui.form;
    });
    function fun_searchgood(obj){
        var objname=$(obj).attr("id");
        var gtpye=2;
        if(objname=="search_project")gtpye=1;
        $(obj).next("ul").empty();
        var keyword=$(obj).val().trim();
        $.post("{php echo $this->createMobileUrl('index',array('op'=>'searchgoods'))}",{gtpye:gtpye,keyword:keyword},function(returnstr){
            console.log(returnstr);
            var result=eval("("+returnstr+")");
            if(result.success){
                var list=result.list;
                var temp='';
                for(var i in list){
                    temp+='<li><a href="JavaScript:addnewproject('+gtpye+','+list[i].id+')">'+list[i].title+'</a></li>';
                }
                if(temp=='')temp='<li><a href="JavaScript:">-</a></li>';
                $(obj).next("ul").html(temp);
                if($(obj).next("ul").is(":hidden"))$(obj).click().focus();
            }
        });
    }
    function Counter(num,obj){
        var vTecla=num;
        var salida=$(obj);
        if(vTecla=='C'){
            salida.val('0');
            if(obj=="#ppl_input_paidfee")fun_paycount();
            return false;
        }

        if(vTecla=='B'){
            var temp1=salida.val();
            salida.val(temp1.substr(0,temp1.length-1));
            if(obj=="#ppl_input_paidfee")fun_paycount();
            return false;
        }
        if(salida.val().length>8){
            return false;
        }
        if(vTecla=='.'){
            if(salida.val().indexOf('.')>-1){
                salida.val(salida.val());
            }else{
                salida.val(salida.val()+vTecla);
            }
        }else if(vTecla=='0'){
            if(salida.val()==0 && salida.val().length==1){
                salida.val(0);
            }else{
                salida.val(salida.val()+vTecla);
            }
        }else{
            if((salida.val()==0 && salida.val().length==1)){
                salida.val(vTecla);
            }else{
                salida.val(salida.val()+vTecla);
            }
        }
        var temp=salida.val();
        if(temp.indexOf('.')>-1){
            var float=temp.split('.');
            if(float[1].length>2){
                salida.val(float[0]+'.'+float[1].substr(0,2));
            }
        }
        if(obj=="#ppl_input_paidfee")fun_paycount();
    }
    function fun_searchmember(obj){
        $(obj).next("ul").empty();
        var keyword=$(obj).val().trim();
        if(!keyword)return;
        $.post("{php echo $this->createMobileUrl('index',array('op'=>'searchmembers'))}",{keyword:keyword},function(returnstr){
            console.log(returnstr);
            var result=eval("("+returnstr+")");
            if(result.success){
                var list=result.list;
                var temp='';
                for(var i in list){
                    temp+='<li><a href="JavaScript:addmember('+list[i].id+')">'+list[i].realname+' - '+list[i].mobile+'</a></li>';
                }
                if(temp=='')temp='<li><a href="JavaScript:">-</a></li>';
                $(obj).next("ul").html(temp);
                if($(obj).next("ul").is(":hidden"))$(obj).click().focus();
            }
        });
    }
    function addmember(memberid){
        var index2=layer.load(1, {shade: [0.1,'#fff']});
        $.post("{php echo $this->createMobileUrl('index',array('op'=>'getmember'))}",{memberid:memberid},function(returnstr){
            layer.close(index2);
            console.log(returnstr);
            var result=eval("("+returnstr+")");
            if(result.success){
                $("#membercardno").val(memberid);
                var member=result.member;
                var temp='<button type="button" class="btn btn-success btn-lg btnmemberbox"> <span>'+(member.cardno ? member.cardno : member.wxcardno )+'</span> <span>'+member.realname+'</span> <div><span>积：</span><span>'+member.credit2+'</span> <span>余：￥</span><span>'+member.cash2+'</span></div></button>';
                $("#membercardbox").html(temp).show();
            }
        });
    }
    function addnewproject(type,id){
        var orderid=parseInt($("#orderid").val());
        if(!orderid){
            layer.confirm('确认要新开订单？', {btn: ['确认','取消']}, function(index){
                layer.close(index);
                openNewOrder();
            });
            return;
        }
        var gooditem=arguments.length>2 ? arguments[2] : "";
        var index2=layer.load(1, {shade: [0.1,'#fff']});
        $.post("{php echo $this->createMobileUrl('index',array('op'=>'getproject'))}",{id:id,gtype:type},function(returnstr){
            layer.close(index2);
            console.log(returnstr);
            var result=eval("("+returnstr+")");
            if(result.success){
                var item=result.item;
                var temp='';
                if(type==1){
                    var commission=item.commission.split(",");
                    var performance=item.performance.split(",");
                    var temp0='',temp1='',temp2='',temp3='';
                    for(var i =0;i<commission.length;i++){
                        var tempary1=commission[i].split("#");
                        var tempary2=performance[i].split("#");
                        temp1+='<input type="button" onclick="selectstaff('+tempary1[0]+',this)" class="form-control staff staff'+i+'" value="选择-'+staffcateAry[tempary1[0]]+'" i="'+i+'" cid="0"/>';

                        if(parseInt(tempary1[1])==1){
                            var p1=Math.round(parseFloat(tempary1[2])*0.01*parseFloat(item.price));
                            temp2+='<input type="text" pernum="'+tempary1[2]+'%" class="form-control commission commission'+i+'" value="'+p1+'"/>';
                            temp0+='<select class="form-control ctype ctype'+i+'" i="'+i+'" onchange="changeCtype(this)" lay-ignore><option value="1#'+tempary1[2]+'%" selected>轮牌</option><option value="2#'+tempary1[3]+'%">指定</option></select>';
                        }else{
                            temp2+='<input type="text" pernum="'+tempary1[2]+'" class="form-control commission commission'+i+'" value="'+tempary1[2]+'"/>';
                            temp0+='<select class="form-control ctype ctype'+i+'" i="'+i+'" onchange="changeCtype(this)" lay-ignore><option value="1#'+tempary1[2]+'" selected>轮牌</option><option value="2#'+tempary1[3]+'">指定</option></select>';
                        }
                        if(parseInt(tempary2[1])==1){
                            var p2=Math.round(parseFloat(tempary2[2])*0.01*parseFloat(item.price));
                            temp3+='<input type="text" pernum="'+tempary2[2]+'%" class="form-control performance performance'+i+'" value="'+p2+'" />';
                        }else{
                            temp3+='<input type="text" pernum="'+tempary2[2]+'" class="form-control performance performance'+i+'" value="'+tempary2[2]+'" />';

                        }
                    }
                    temp+='<tr gid="'+item.id+'" goodtype="1" mid="'+gooditem.id+'"><td>'+item.title+'</td>';
                    temp+='<td>'+temp1+'</td>';
                    temp+='<td>'+temp0+'</td>';
                    temp+='<td>'+temp2+'</td>';
                    temp+='<td>'+temp3+'</td>';
                    temp+='<td><input type="text" class="form-control pprice" readonly value="'+item.price+'" /></td>';
                    temp+='<td><input type="number" class="form-control pnum" readonly oninput="checkInputNum(this)" value="1" /></td>';
                    temp+='<td><input type="text" class="form-control pdiscount" oninput="checkInputNum(this)" value="100" /></td>';
                    temp+='<td><input type="text" class="form-control pfee" oninput="checkInputNum(this)" value="'+item.price+'" /></td>';
                    temp+='<td style="text-align: right"><button type="button" class="btn btn-danger btn-sm" onclick="deleterow(this)">&times;</button></td></tr>';
                }else{

                    temp+='<tr gid="'+item.id+'" goodtype="0" mid="'+gooditem.id+'"><td>'+item.title+'</td>';
                    temp+='<td><input type="button" onclick="selectstaff(0,this)" class="form-control staff staff0" i="0" value="选择员工"/></td>';
                    temp+='<td></td>';
                    temp+='<td><input type="text" class="form-control commission commission0" value="'+item.marketprice+'" /></td>';
                    temp+='<td><input type="text" class="form-control performance performance0" value="'+item.marketprice+'" /></td>';
                    temp+='<td><input type="text" class="form-control pprice" readonly value="'+item.marketprice+'" /></td>';
                    temp+='<td><input type="number" class="form-control pnum" oninput="checkInputNum(this)" value="1" /></td>';
                    temp+='<td><input type="text" class="form-control pdiscount" oninput="checkInputNum(this)" value="100" /></td>';
                    temp+='<td><input type="text" class="form-control pfee" oninput="checkInputNum(this)" value="'+item.marketprice+'" /></td>';
                    temp+='<td style="text-align: right"><button type="button" class="btn btn-danger btn-sm" onclick="deleterow(this)">&times;</button></td></tr>';
                }
                if($("#goodprolist tr").size()==0){
                    $("#goodprolist").append(temp);
                }else{
                    $(temp).insertBefore($("#goodprolist tr").eq(0));
                }
                $("#goodprolist tr").each(function(index){
                    $(this).attr("index",index);
                });
                if(gooditem){
                    var _target=$("tr[mid='"+gooditem.id+"']");
                    _target.find(".pnum").val(gooditem.num);
                    _target.find(".pdiscount").val(gooditem.discount);
                    _target.find(".pfee").val(fee2num(gooditem.total_fee));
                    var comAry=gooditem.performance.split("|@|");
                    if(type==2){
                        var tempAry=comAry[0].split("|#|");
                        _target.find(".staff0").val(stafflist[tempAry[0]]).attr("cid",tempAry[0]);
                        _target.find(".commission0").val(tempAry[2]);
                        _target.find(".performance0").val(tempAry[3]);
                    }else{
                        for(var i=0; i< comAry.length;i++){
                            var tempAry=comAry[i].split("|#|");
                            console.log(comAry[i]);
                            _target.find(".staff"+i).val(stafflist[tempAry[0]]).attr("cid",tempAry[0]);
                            _target.find(".ctype"+i).val(tempAry[1]);
                            _target.find(".commission"+i).val(tempAry[2]);
                            _target.find(".performance"+i).val(tempAry[3]);
                        }
                    }
                }
                countfee();
            }else{
                layer.msg(result.msg,{icon:2,time:1000});
                return;
            }
        });
    }
    function selectstaff(stype,obj){

        var index2=layer.load(1, {shade: [0.1,'#fff']});
        $.post("{php echo $this->createMobileUrl('index',array('op'=>'getstaff'))}",{stype:stype},function(returnstr){
            layer.close(index2);
            console.log(returnstr);
            var result=eval("("+returnstr+")");
            if(result.success) {
                var list = result.list;
                $("#staffselect ul").empty();
                var temp='';
                var classname=$(obj).attr("i");
                var indexs=$(obj).parent().parent().attr("index");
                for(var i in list){
                    temp+='<li><a href="JavaScript:selectStaffto(\''+list[i].realname+'\','+list[i].id+',\''+classname+'\','+indexs+')">'+list[i].realname+'</a></li>';
                }
                temp+='<li role="separator" class="divider"></li><li><a href="JavaScript:closeStaff()">关闭</a></li>';
                $("#staffselect ul").append(temp);
                $("#staffselect").addClass("open");
                var pos=$(obj).offset();
                $("#staffselect").show().css({"left":pos.left,"top":pos.top+34});
            }else{
                layer.msg(result.msg,{icon:2,time:1000});
                return;
            }
        });
    }
    function changeCtype(obj){
        checkInputNum(obj);
    }
    function checkInputNum(obj){
        var target=$(obj).parent().parent();
        var price=str2num(target.find(".pprice").val());
        var discount=(parseFloat(target.find(".pdiscount").val())*0.01);
        var num=parseInt(target.find(".pnum").val());
        var fee=parseFloat(target.find(".pfee").val());
        var classname=$(obj).attr("class");
        if(classname.indexOf("pnum")>-1){
            var val=parseInt($(obj).val());
            var tempfee=((val*price*discount)*0.01).toFixed(2);
            target.find(".pfee").val(tempfee);
            num=val;
            fee=tempfee;
        }else if(classname.indexOf("pdiscount")>-1){
            var val=parseInt(parseFloat($(obj).val()));
            if(val>100)$(obj).val("100");
            val=(parseFloat($(obj).val())*0.01);
            var tempfee=((num*price*val)*0.01).toFixed(2);
            target.find(".pfee").val(tempfee);
            fee=tempfee;
        }else if(classname.indexOf("pfee")>-1){
            var val=str2num($(obj).val());
            var tempdis=(str2num(val / price*num)).toFixed(2);
            target.find(".pdiscount").val(tempdis);
            fee=parseFloat($(obj).val());
        }
        target.find(".commission").each(function(index){
            var pernumval=target.find(".ctype"+index+" option:selected").val();
            var tempary=pernumval.split("#");
            var pernum =tempary[1];
            var tempfee=0;
            if(pernum){
                if(pernum.indexOf("%")>-1){
                    tempfee=Math.round(parseInt(pernum.replace('%',''))*0.01*fee);
                }else{
                    tempfee=Math.round(parseInt(pernum)*num);
                }
                $(this).val(tempfee);
            }
        });
        target.find(".performance").each(function(){
            var pernum=$(this).attr("pernum");
            var tempfee=0;
            if(pernum){
                if(pernum.indexOf("%")>-1){
                    tempfee=Math.round(parseInt(pernum.replace('%',''))*0.01*fee);
                }else{
                    tempfee=Math.round(parseInt(pernum)*num);
                }
                $(this).val(tempfee);
            }
        });
        countfee();
    }
    function closeStaff(){
        $("#staffselect").removeClass("open").hide();
    }
    function selectStaffto(realname,id,classname,indexs){
        console.log(realname+','+id+','+classname+','+indexs);
        $("#goodprolist tr[index='"+indexs+"']").find(".staff"+classname).val(realname).attr("cid",id);
        $("#staffselect").removeClass("open").hide();
    }
    function deleterow(obj){
        layer.confirm('确认删除？', {}, function(indexd){
            layer.close(indexd);
            var mid=$(obj).parent().parent().attr("mid");
            if(mid=="undefined"){
                $(obj).parent().parent().remove();
                return;
            }
            var index2=layer.load(1, {shade: [0.1,'#fff']});
            $.post("{php echo $this->createMobileUrl('index',array('op'=>'deleteordergoods'))}",{mid:mid},function(returnstr) {
                layer.close(index2);
                console.log(returnstr);
                var result = eval("(" + returnstr + ")");
                if (result.success) {
                    $(obj).parent().parent().remove();
                }else{
                    layer.msg(result.msg,{icon:2,time:1500});
                    return;
                }
            });


        });
    }
    function countfee(){
        var totalfee=0;
        $("#goodprolist tr").each(function(){
            var fee=str2num($(this).find(".pfee").val());
            totalfee+=fee;
        });
        $("#totalfee").text(Math.round(totalfee*0.01).toFixed(2));
    }
    function openNewOrder(){
        var index2=layer.load(1, {shade: [0.1,'#fff']});
        $.post("{php echo $this->createMobileUrl('index',array('op'=>'neworder'))}",{},function(returnstr) {
            layer.close(index2);
            console.log(returnstr);
            var result = eval("(" + returnstr + ")");
            if (result.success) {
                var orderid=result.orderid;
                $("#orderid").val(orderid);
                $("#orderno").text(result.serialnum);
                $("#holdorder").text("挂单");
            }else{
                layer.msg(result.msg,{icon:2,time:1000});
                return;
            }
        });
    };

    function fun_holdOrder(){
        var orderid=$("#orderid").val();
        if(!orderid){
            openNewOrder();
            return;
        }
        if($("#goodprolist tr").size()==0)return;
        var tempgood=[];
        $("#goodprolist tr").each(function(){
            var temp='',commission=[],performance=[];
            var gtype=$(this).attr("goodtype");
            var gid=$(this).attr("gid");
            var mid=$(this).attr("mid")!="undefined" ? $(this).attr("mid") : 0;
            var price=$(this).find(".pprice").val();
            var num=$(this).find(".pnum").val();
            var discount=$(this).find(".pdiscount").val();
            var fee=$(this).find(".pfee").val();
            //gid,price,num,discount,fee,commission(sid,fee),performance(sid,fee);
            var len=$(this).find(".staff").size();
            for(var i=0; i<len;i++){
                var cid=$(this).find(".staff"+i).attr("cid") ? $(this).find(".staff"+i).attr("cid") : 0;
                var temp_ctype=$(this).find(".ctype"+i).val() ? $(this).find(".ctype"+i).val() : 0;
                var temp_com=$(this).find(".commission"+i).val();
                var temp_per=$(this).find(".performance"+i).val();
                commission.push(cid+"|#|"+temp_ctype+"|#|"+temp_com+"|#|"+temp_per);
            }
            //console.log(len+","+commission.join("|@|"));
            temp=mid+'||'+gid+'||'+gtype+'||'+price+'||'+num+'||'+discount+'||'+fee+'||'+commission.join("|@|");
            tempgood.push(temp);
        });

        var memberid=$("#membercardno").val();
        var prama={"orderid":orderid,"memberid":memberid,"goods":tempgood.join(",")}
        var paystart= arguments.length ? true : false;
        var index2=layer.load(1, {shade: [0.1,'#fff']});
        $.post("{php echo $this->createMobileUrl('index',array('op'=>'holdorder'))}",prama,function(returnstr) {
            layer.close(index2);
            console.log(returnstr);
            var result = eval("(" + returnstr + ")");
            if (result.success) {
                if(paystart){
                    fun_startPay(orderid);
                }
                resetOrder();
            }else{
                layer.msg(result.msg,{icon:2,time:1000});
                return;
            }
        });
    }
    function fun_selectholdorder(){
        layer.open({
            type: 1,
            title:"取回订单",
            area:'780px',
            skin: 'layui-layer-rim',
            content:$(".modal_selectorder").show(),
            success: function(layero, index){
                var index2=layer.load(1, {shade: [0.1,'#fff']});
                $.post("{php echo $this->createMobileUrl('index',array('op'=>'getholdorderlist'))}",{},function(returnstr){
                    layer.close(index2);
                    console.log(returnstr);
                    var result=eval("("+returnstr+")");
                    if(result.success){
                        var list=result.list;
                        $(".modal_selectorderlist").empty();
                        for(var i in list){
                            var temp='<li oid="'+list[i].id+'" onclick="mda_selectOrder('+list[i].id+')"><span class="pull-right">'+fromatTime(list[i].createtime)+'</span> <span class="layui-badge-dot layui-bg-green"></span> 单号：'+list[i].serialnum+' </li>';
                            $(".modal_selectorderlist").append(temp);
                        }
                    }else{
                        layer.msg(result.msg,{icon:2,time:1000});
                        return false;
                    }

                });
                $(".modal_selectorderbtn1").bind("click",function(){
                    if(!$(".modal_selectorderlist .isselect").size()){
                        layer.msg("请选择订单",{icon:2,time:1000});
                        return ;
                    }
                    if($("#orderid").val()){
                        layer.confirm('已有订单在处理，是否挂单？', {}, function(indexd){
                            layer.close(indexd);
                            fun_holdOrder();
                        });
                        return;
                    }
                    var orderid=$(".modal_selectorderlist .isselect").attr("oid");
                    fun_formatorder(orderid);
                    layer.closeAll();
                });
                $(".modal_selectorderbtn2").bind("click",function(){
                    if(!$(".modal_selectorderlist .isselect").size()){
                        layer.msg("请选择订单",{icon:2,time:1000});
                        return ;
                    }
                    var orderid=$(".modal_selectorderlist .isselect").attr("oid");
                    layer.confirm('确认删除此订单？', {}, function(indexd){
                        layer.close(indexd);
                        var index2=layer.load(1, {shade: [0.1,'#fff']});
                        $.post("{php echo $this->createMobileUrl('index',array('op'=>'clearorder'))}",{orderid:orderid},function(returnstr){
                            layer.close(index2);
                            var result=eval("("+returnstr+")");
                            if(result.success){
                                $(".modal_selectorderlist .isselect").remove();
                                $(".modal_selectorderlist2").empty();
                            }
                        });

                    });
                });
                $(".modal_selectorderbtn3").bind("click",function(){
                    layer.close(index);
                });
            },
            end:function(){
                $(".modal_selectorder").hide();
                $(".modal_selectorderbtn1").unbind("click");
                $(".modal_selectorderbtn2").unbind("click");
                $(".modal_selectorderbtn3").unbind("click");
            }
        });
    }
    function mda_selectOrder(orderid){
        $(".modal_selectorderlist li[oid='"+orderid+"']").addClass("isselect").siblings().removeClass("isselect");
        var index2=layer.load(1, {shade: [0.1,'#fff']});
        $.post("{php echo $this->createMobileUrl('index',array('op'=>'getorderdetail'))}",{orderid:orderid},function(returnstr){
            layer.close(index2);
            console.log(returnstr);
            var result=eval("("+returnstr+")");
            if(result.success){
                var list=result.goods;
                $(".modal_selectorderlist2").empty();
                for(var i in list){
                    var temp='<tr><td>'+list[i].goodsn+'</td><td>'+list[i].title+'</td><td>'+list[i].num+'</td><td>'+fee2num(list[i].total_fee)+'</td></tr>';
                    $(".modal_selectorderlist2").append(temp);
                }
            }else{
                layer.msg(result.msg,{icon:2,time:1000});
                return false;
            }
        })
    }
    function fun_formatorder(orderid){
        var index2=layer.load(1, {shade: [0.1,'#fff']});
        $.post("{php echo $this->createMobileUrl('index',array('op'=>'getorderdetail'))}",{orderid:orderid},function(returnstr){
            layer.close(index2);
            var result=eval("("+returnstr+")");
            if(result.success){
                var trade=result.trade;
                $("#orderid").val(orderid);
                $("#orderno").text(trade.serialnum);
                $("#holdorder").text("挂单");
                /**/
                var goods=result.goods;
                for(var i in goods){
                    var gtype=2;
                    if(parseInt(goods[i].gtype)){
                        gtype=1;
                    }
                    addnewproject(gtype,goods[i].goodid,goods[i]);
                }
            }
        });
    }
    function resetOrder(){
        $("#totalfee").text("0.00");
        $("#membercardno").val("0");
        $("#orderid").val("");
        $("#orderno").text("请先开单");
        $("#holdorder").text("开单");
        $("#goodprolist").empty();
    }
    function fun_modal(param){
        layer.open({
            type: 1,
            title:param.title,
            area:'320px',
            shadeClose:true,
            skin: 'layui-layer-rim',
            content:$(".modal_counter").show(),
            success: function(layero, index){
                if(!param.type){
                    $("#modal_doc").hide();
                }else{
                    $("#modal_doc").show();
                }
                if(param.val){
                    $('#moadConterInput').val(param.val);
                    $('#moadConterInput').select();
                }else{
                    $('#moadConterInput').val('');
                }
                if(param.tips){
                    $('#moadConterInput').attr("placeholder",param.tips);
                }else{
                    $('#moadConterInput').attr('placeholder','');
                }
                $("#modal_cantrl").on("click",function(){
                    layer.close(index);
                });
                $("#modal_sure").on("click",function(){
                    if(typeof(param.success)=='function'){param.success($('#moadConterInput').val(),index);}
                });
            },
            end:function(){
                $(".modal_counter").hide();
                param=null;
                $("#modal_cantrl").unbind("click");
                $("#modal_sure").unbind("click");
            }
        });
    }
</script>